home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / UIFlow 1.0.1 / UIFlow Source / CFDFront / TNewSegment.cp < prev    next >
Encoding:
Text File  |  1992-02-21  |  11.9 KB  |  328 lines  |  [TEXT/MPS ]

  1. #pragma segment CObj
  2. //**********************************************************************
  3. //    TNewSectionCommand - Methods
  4. //**********************************************************************
  5. // -------------------------------------------------------------------------------------------------
  6. //    Initialize the NewSegmentCommand.
  7. // -------------------------------------------------------------------------------------------------
  8. void TNewSectionCommand::INewSectionCommand (TGeomView * itsGeometry, TCFDFrontDocument * tDoc)
  9.     {
  10.     fGeomView    = itsGeometry;                                                                                // store the geometry
  11.     fCDocument    = tDoc;                                                                                            // get the document
  12.     fPointMatrix    =    fCDocument->fPointMatrix;                                                        // store pointer to matrix object
  13.  
  14.     fConstrainsMouse = true;                                                                                    // constrain the mouse
  15.     fGeomView->lastCmd = 0;                                                                                    // this is a newSegment
  16.     saveDeleted    = NULL;
  17.     fPoint            = NULL;
  18.     inherited::ICommand (cNewSecCommand,                                                            // init the command
  19.                     fCDocument, fGeomView, fGeomView->GetScroller(true));
  20.     }
  21.  
  22. // --------------------------------------------------------------------------------------------------
  23. //     Create the point
  24. // --------------------------------------------------------------------------------------------------
  25. TPoint * TNewSectionCommand::CreatePoint (TPoint * tPt, Point * mMouse)
  26.     {
  27.     TGPoint * sPt;
  28.     short        type;
  29.     
  30.     sPt = new TGPoint;                                                                                                // allocate the memory
  31.     if (sPt == NULL)                                                                                                    // could not add a point
  32.         return NULL;
  33.     
  34.     type = tPt->GetSectionType();
  35.     fSide->SnaptoSection(mMouse);                                                                            // snap the point to line
  36.     sPt->IPoint(mMouse->v,mMouse->h,type,fGeomView->fMagnify);                            // initialize the point
  37.     return (TPoint *) sPt;
  38.     }
  39.     
  40. //**********************************************************************
  41. //    TNewSegmentCommand - Methods
  42. //**********************************************************************
  43. // -------------------------------------------------------------------------------------------------
  44. //    NewSegmentCommand Methods.
  45. // -------------------------------------------------------------------------------------------------
  46. // -------------------------------------------------------------------------------------------------
  47. //    Initialize the NewSegmentCommand.
  48. // -------------------------------------------------------------------------------------------------
  49. void TNewSegmentCommand::INewSegmentCommand (TGeomView * itsGeometry, TCFDFrontDocument * tDoc)
  50.     {
  51.     fGeomView    = itsGeometry;                                                                                // store the geometry
  52.     fCDocument    = tDoc;                                                                                            // get the document
  53.     fPointMatrix    =    fCDocument->fPointMatrix;                                                        // store pointer to matrix object
  54.  
  55.     fConstrainsMouse = true;                                                                                    // constrain the mouse
  56.     fGeomView->lastCmd = 0;                                                                                    // this is a newSegment
  57.     saveDeleted    = NULL;
  58.     fPoint            = NULL;
  59.     inherited::ICommand (cNewSegCommand,                                                            // init the command
  60.                     fCDocument, fGeomView, fGeomView->GetScroller(true));
  61.     }
  62.  
  63. // -------------------------------------------------------------------------------------------------
  64. //    tracking feedback. limit the mouse motion to the geometry not including the border.
  65. // -------------------------------------------------------------------------------------------------
  66. pascal void TNewSegmentCommand::TrackConstrain (VPoint * /*ancorPoint*/, 
  67.             VPoint * /*previousPoint*/, VPoint * nextPoint)    
  68.     {
  69.     if (nextPoint->v <= cGeomViewBorder)                                                            // limit the verticle dimension
  70.         nextPoint->v = cGeomViewBorder + 1;
  71.     else
  72.         if (nextPoint->v >= fGeomView->fSize.v - cGeomViewBorder)
  73.             nextPoint->v = fGeomView->fSize.v - cGeomViewBorder;
  74.  
  75.     if (nextPoint->h <= cGeomViewBorder)                                                            // limit the horizontal dimension
  76.         nextPoint->h = cGeomViewBorder + 1;
  77.     else
  78.         if (nextPoint->h >= fGeomView->fSize.h - cGeomViewBorder)
  79.             nextPoint->h = fGeomView->fSize.h - cGeomViewBorder;
  80. }
  81.  
  82. // -------------------------------------------------------------------------------------------------
  83. //    tracking feedback.
  84. // -------------------------------------------------------------------------------------------------
  85. pascal TCommand * TNewSegmentCommand::TrackMouse (TrackPhase aTrackPhase, 
  86.                     VPoint * /*ancorPoint*/, VPoint * /*previousPoint*/, VPoint * nextPoint, 
  87.                     Boolean mouseDidMove)
  88.     {
  89.     Point tmp;
  90.     tmp = VPtToPt(nextPoint);                                                                                // save nextPoint
  91.     
  92.     if (mouseDidMove)
  93.         {        
  94.         Point tmp1;
  95.         tmp1 = AntiTransform(tmp,fGeomView->fMagnify);                                        // convert nextPoint to viewpoint                                                                
  96.         ((TInformationView *) fCDocument->fInfoView)->StatusString(tmp1);            // display the status string
  97.  
  98.         if (aTrackPhase == trackRelease)                                                                    // if mouse is released
  99.             fLocation = AntiTransform(tmp,fGeomView->fMagnify);
  100.         }
  101.     return (TCommand *) this;
  102.     }
  103.  
  104. // --------------------------------------------------------------------------------------------------
  105. //    Do it.
  106. // --------------------------------------------------------------------------------------------------
  107. pascal void TNewSegmentCommand::DoIt (void)    
  108.     {
  109.     PointInfo    sInfo, oInfo;                                                                                            // draw structures
  110.     Point         mMouse;
  111.     TPoint         * tPt;                                                                                                    // current point
  112.     TGPoint    *    oPt;                                                                                                    // point on opposite boundry
  113.     short        theSide;
  114.     short        temp;
  115.     
  116.     done            =    false;
  117.     mMouse     =     fLocation;
  118.     HLock((Handle) this);
  119.     if ((tPt = (TPoint *) fPointMatrix->FindSection(&mMouse)) == NULL)                    // on a boundry?
  120.         {
  121.         HUnlock((Handle) this);
  122.         return;
  123.         }
  124.     HUnlock((Handle) this);
  125.         
  126.     fSide = (TBoundry *) fPointMatrix->GetCurrentBoundry();                                    // what boundry?
  127.     theSide = fSide->GetSide();                                                                                    // which side
  128.  
  129.     if ((temp = fPointMatrix->ObsBaffInLine(fSide)) != 0)
  130.         {
  131.         char    msg[80];
  132.         
  133.         if (temp == 1)
  134.             sprintf(msg,"Obstacle");
  135.         else
  136.             sprintf(msg,"Baffle");
  137.         SysBeep (3);
  138.         TWarning * tWarning;
  139.         TWindow    * aWindow;
  140.         
  141.         aWindow = NewTemplateWindow(kWarnMe, fCDocument);
  142.         tWarning = (TWarning *) aWindow->FindSubView('WARN');
  143.         tWarning->IWarning(8,msg);
  144.         tWarning->ShowWarning();
  145.         return;
  146.         }
  147.         
  148.     HLock((Handle) this);
  149.     fPoint = this->CreatePoint(tPt,&mMouse);    
  150.     HUnlock((Handle) this);
  151.     if (fPoint == NULL)
  152.         return;
  153.         
  154.     fPoint->RememberPoint();    
  155.     HLock((Handle) this);
  156.     if ((oPt = fPointMatrix->GetOpposite(&mMouse,&sInfo,&oInfo)) == NULL)                // create opposite point
  157.         {
  158.         HUnlock((Handle) this);
  159.         delete fPoint;
  160.         return;
  161.         }
  162.     
  163.     HUnlock((Handle) this);
  164.     done = true;
  165.     fGeomView->Focus();
  166.     TPoint * save1, * save2;
  167.     save1 = sInfo.left;
  168.     save2 = oInfo.left;
  169.     
  170.     fRow                 =    sInfo.row            = fPointMatrix->GetRow();                                // set the row
  171.     fColumn            =    sInfo.column        = fPointMatrix->GetColumn();                            // set the column
  172.     sInfo.gridOnly    = oInfo.gridOnly     = false;
  173.     sInfo.above        = oInfo.above         = NULL;
  174.     sInfo.below        = sInfo.below         = NULL;
  175.     sInfo.magnify    = oInfo.magnify        = fGeomView->fMagnify;
  176.     sInfo.right        = tPt;
  177.     
  178.     HLock((Handle) this);
  179.     this->Draw(sInfo.right, oInfo.right, theSide, &sInfo, &oInfo);
  180.     
  181.     if (!fPointMatrix->AddAt(fPoint,oPt,sInfo.row,sInfo.column))                                // add it
  182.         {
  183.         delete fPoint;                                                                                                    // can't add it
  184.         delete oPt;
  185.         this->Draw(sInfo.right,oInfo.right,theSide, &sInfo, &oInfo);
  186.         return;
  187.         }
  188.     
  189.     this->Draw(fPoint,oPt,theSide, &sInfo, &oInfo);
  190.     
  191.     if (fPointMatrix->IsShown() && (theSide == cLeft || theSide == cRight))                // do a grid line?
  192.         fPointMatrix->OneRowDo(DrawAllPoints,&sInfo);
  193.     else if (fPointMatrix->IsShown())
  194.         fPointMatrix->OneColumnDo(DrawPoint,&sInfo);
  195.     else
  196.         {
  197.         DrawPoint(fPoint,&sInfo);
  198.         DrawPoint(oPt,&oInfo);
  199.         }
  200.     
  201.     HUnlock((Handle) this);
  202.  
  203.     sInfo.row += 1;
  204.     sInfo.column += 1;
  205.     sInfo.left = fPoint;
  206.     oInfo.left = oPt;
  207.     this->Draw(sInfo.right,oInfo.right,theSide, &sInfo, &oInfo);
  208.     
  209.     sInfo.left = save1;
  210.     oInfo.left = save2;
  211.     
  212.     if (fGeomView->fSPoint != NULL)
  213.         fPointMatrix->DoHighlight();                                                                                // unhighlight selection
  214.         
  215. //    select the new point
  216.     fGeomView->UnSelect();                                                                                        // unselect old point
  217.     fGeomView->Select(fPoint,false,fSide);                                                                // select new point
  218.     fPointMatrix->DoHighlight();                                                                                    // highlight point
  219.         
  220.     ((TInformationView *) fCDocument->fInfoView)->ShowDimension();                        // show number of segments
  221.     ((TInformationView *) fCDocument->fInfoView)->StatusString(fPoint->fStart);    // display the status string return;
  222.     }
  223.  
  224. // --------------------------------------------------------------------------------------------------
  225. //     Create the point
  226. // --------------------------------------------------------------------------------------------------
  227. TPoint * TNewSegmentCommand::CreatePoint (TPoint * tPt, Point * mMouse)
  228.     {
  229.     TSegPoint *  sPt, * sPt1;
  230.     WallRecord     i;
  231.     short             type;
  232.     
  233.     sPt = new TSegPoint;                                                                                            // allocate the memory
  234.     if (sPt == NULL)                                                                                                    // could not add a point
  235.         return NULL;
  236.     
  237.     type = tPt->GetSectionType();                                                                                // get the type
  238.     fSide->SnaptoSection(mMouse);                                                                            // snap the point to line
  239.     sPt->IPoint(mMouse->v,mMouse->h,type,fGeomView->fMagnify);                            // initialize the point
  240.     
  241.     sPt1 = fPointMatrix->FindSegment(tPt,fSide);                                                        // find the old segment
  242.     i = sPt1->GetData();                                                                                                // get old data
  243.     sPt->SetData(i);                                                                                                    // set the new the same
  244.     
  245.     return (TPoint *) sPt;
  246.     }
  247.     
  248. // --------------------------------------------------------------------------------------------------
  249. //     Draw the new segment/section/grid line
  250. // --------------------------------------------------------------------------------------------------
  251. void TNewSegmentCommand::Draw (TPoint * sPt, TPoint * oPt, short theSide, PointInfo * sInfo, PointInfo * oInfo)
  252.     {
  253.     HLock((Handle) this);
  254.     if (fPointMatrix->IsShown() && (theSide == cLeft || theSide == cRight))                // do a grid line?
  255.         fPointMatrix->OneRowDo(DrawAllLines,sInfo);
  256.     else if (fPointMatrix->IsShown())
  257.         fPointMatrix->OneColumnDo(DrawLine,sInfo);
  258.     else
  259.         {
  260.         sInfo->noGrid = fPointMatrix->IsShown();
  261.         oInfo->noGrid = sInfo->noGrid;
  262.         DrawLine(sPt,sInfo);
  263.         DrawLine(oPt,oInfo);
  264.         }
  265.     HUnlock((Handle) this);
  266.     }
  267.     
  268. // --------------------------------------------------------------------------------------------------
  269. //     Undo it.
  270. // --------------------------------------------------------------------------------------------------
  271. pascal void TNewSegmentCommand::UndoIt (void)
  272.     {
  273.     fGeomView->Focus();
  274.     if (!done)
  275.         return;
  276.         
  277.     if (fGeomView->fSPoint != NULL)
  278.         fPointMatrix->DoHighlight();                                                                                // unhighlight selection
  279.         
  280.     fGeomView->UnSelect();                                                                                        // unselect old point
  281.  
  282.     fPointMatrix->SetCurrent(fPoint);
  283.     saveDeleted = fPointMatrix->DeleteCurrent(fSide);
  284.     fPoint = NULL;
  285.     
  286.     ((TInformationView *) fCDocument->fInfoView)->ShowDimension();                        // show number of segments
  287.     return;
  288.     }
  289.  
  290. // --------------------------------------------------------------------------------------------------
  291. //     Redo it.
  292. // --------------------------------------------------------------------------------------------------
  293. pascal void TNewSegmentCommand::RedoIt (void)
  294.     {
  295.     fGeomView->Focus();
  296.     if (!done)
  297.         return;
  298.     
  299.     fPoint = fPointMatrix->AddLine(saveDeleted,fSide,fRow,fColumn);                        // add back in
  300.     fPointMatrix->SetCurrent(fPoint);
  301.     
  302.     ((TInformationView *) fCDocument->fInfoView)->ShowDimension();                        // show number of segments
  303.     ((TInformationView *) fCDocument->fInfoView)->StatusString(fPoint->fStart);    // display the status string return;
  304.     return;
  305.     }
  306.  
  307. // --------------------------------------------------------------------------------------------------
  308. //     Free NewSegment
  309. // --------------------------------------------------------------------------------------------------
  310. pascal void TNewSegmentCommand::Free (void)
  311.     {
  312.     if (!fCmdDone)                                                                                                            // undo the add
  313.         {                                                                                                                            // so free all the new objects
  314.         short x, side;
  315.         TPoint * t;
  316.         
  317.         side = fSide->GetSide();
  318.         for (x = (short) saveDeleted->fSize; x > 0; x--)
  319.             {
  320.             t = (TPoint *) saveDeleted->At(x);
  321.             saveDeleted->Delete(t);
  322.             FreeIfObject(t);
  323.             }
  324.         if (side == cLeft || side == cRight)
  325.             FreeIfObject(saveDeleted);
  326.         }
  327.     inherited::Free();
  328.     }